package cn.csdj.sism.web;

import cn.csdj.sism.pojo.Dept;
import cn.csdj.sism.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门控制器
 * 夏康
 */
@CrossOrigin
@Configuration
@RequestMapping("/dept")
public class DeptController {

    //注入部门业务层
    @Autowired
    private DeptService deptService;

    /**
     * 添加部门
     * @param dept
     * @return
     */

    @PostMapping
    public int Insert(@RequestBody Dept dept){
        return deptService.insert(dept);
    }

    /**
     * 删除部门
     * @param id
     * @return
     */

    @DeleteMapping("/{id}")
    public int deleteById(@PathVariable Integer id) {
        return deptService.deleteById(id);
    }
    /**
     * 修改部门
     * @param dept
     * @return
     */
    @PutMapping
    public int update(@RequestBody Dept dept){
        return deptService.update(dept);
    }

    /**
     * 查询部门
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Dept selectById(@PathVariable Integer id){
        return deptService.selectById(id);
    }
    /**
     * 查询全部部门
     * @return
     */
    @GetMapping
    public List<Dept> selectAll(){
        return deptService.selectAll();
    }
}
